package com.sskj.login.presenter;

import android.text.TextUtils;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.login.bean.LoginBean;
import com.sskj.login.http.HttpConfig;
import com.sskj.login.ui.activity.LoginActivity;


public class LoginActivityPresenter extends BasePresenter<LoginActivity> {


    /**
     * 密码登录
     *
     * @param mobile 手机号/邮箱号
     * @param opwd   密码
     * @return
     */
    public void login(String mcode, String mobile, String opwd, String google_code, String secret) {

        httpService.login(mcode, mobile, opwd, google_code, secret).execute(new JsonCallBack<HttpData<LoginBean>>(this) {
            @Override
            public void onSuccess(Response<HttpData<LoginBean>> response) {
                HttpData<LoginBean> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    if (!TextUtils.isEmpty(httpData.getData().getOriginToken()) && !httpData.getData().getOriginToken().equals("0")) {
                        mView.loginSuccess(httpData.getData());
                    } else {
                        mView.googleCheck(httpData.getData().getSecret());
                    }
                }
            }
        });
    }


}
